var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("GlobalParams"),
    n = cc._decorator,
    i = n.ccclass,
    r =
        (n.property,
            (function () {
                function e() {
                    (this.sounds = {}),
                        (this.fight_sounds = {}),
                        (this.enabled = !0),
                        (this.music = ""),
                        (this._sfxVolume = -1),
                        (this.musicVolume = 0.5);
                }
                var t;
                return (
                    (t = e),
                    (e.getInstance = function () {
                        return this.instance || (this.instance = new t()), this.instance;
                    }),
                    (e.prototype.addSound = function (e, t) {
                        this.sounds[e] = t;
                    }),
                    (e.prototype.addFightSound = function (e, t) {
                        this.fight_sounds[e] = t;
                    }),
                    (e.prototype.playFx = function (e, t) {
                        if ((void 0 === t && (t = !1), this.enabled)) {
                            var o;
                            o = a.GlobalParams.gameSound.value ? 1 : 0;
                            var n = 0;
                            return (
                                this.sounds[e]
                                    ? (n = cc.audioEngine.play(this.sounds[e], t, o))
                                    : this.fight_sounds[e] && (n = cc.audioEngine.play(this.fight_sounds[e], t, o)),
                                n
                            );
                        }
                    }),
                    (e.prototype.playMusic = function (e) {
                        (this.music = e),
                            a.GlobalParams.gameMusic.value &&
                            this.enabled &&
                            (this._sfxVolume && cc.audioEngine.stop(t.getInstance()._sfxVolume),
                                this.sounds[e]
                                    ? (this._sfxVolume = cc.audioEngine.play(this.sounds[e], !0, this.musicVolume))
                                    : (this._sfxVolume = cc.audioEngine.play(this.fight_sounds[e], !0, this.musicVolume)));
                    }),
                    (e.prototype.setMusicVolume = function (e) {
                        this._sfxVolume > -1 && cc.audioEngine.setVolume(this._sfxVolume, e), (this.musicVolume = e);
                    }),
                    (e.prototype.setEnabled = function (e) {
                        (this.enabled = e), this.enabled ? this.playMusic(this.music) : cc.audioEngine.stopAll();
                    }),
                    (e.prototype.getEnable = function () {
                        return this.enabled;
                    }),
                    (e.loadSounds = function (e) {
                        cc.loader.loadResDir("sound", cc.AudioClip, function (o, a) {
                            for (var n = 0; n < a.length; n++) t.getInstance().addSound(a[n].name, a[n]);
                            e();
                        });
                    }),
                    (e.ButtonSound = function () {
                        t.getInstance().playFx(a.GlobalParams.btn_sound);
                    }),
                    (e.playGameBGM = function () {
                        t.stopMusic(), t.getInstance().playMusic(a.GlobalParams.gameMusicName);
                    }),
                    (e.stopMusic = function () {
                        cc.audioEngine.stop(t.getInstance()._sfxVolume);
                    }),
                    (t = oo([i], e))
                );
            })());
o.default = r;
